package com.ruoyi.slope.warning.info.service.impl;

import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.slope.gateway.domain.SlopeGatewayInfo;
import com.ruoyi.slope.gateway.service.impl.SlopeGatewayInfoServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.slope.warning.info.mapper.SlopeWarningInfoMapper;
import com.ruoyi.slope.warning.info.domain.SlopeWarningInfo;
import com.ruoyi.slope.warning.info.service.ISlopeWarningInfoService;

/**
 * 预警信息Service业务层处理
 * 
 * @author psy
 * @date 2025-04-27
 */
@Service
public class SlopeWarningInfoServiceImpl implements ISlopeWarningInfoService 
{
    @Autowired
    private SlopeWarningInfoMapper slopeWarningInfoMapper;
    @Autowired
    private SlopeGatewayInfoServiceImpl slopeGatewayInfoServiceImpl;

    public void finish(SlopeWarningInfo slopeWarningInfo){
        updateSlopeWarningInfo(slopeWarningInfo);
        List<SlopeWarningInfo> list = selectSlopeWarningInfoList(slopeWarningInfo);

        SlopeGatewayInfo slopeGatewayInfo = new SlopeGatewayInfo();
        slopeGatewayInfo.setDeptId(slopeWarningInfo.getDeptId());
        if (list != null && !list.isEmpty()){
             List<SlopeGatewayInfo> list1 = slopeGatewayInfoServiceImpl.selectSlopeGatewayInfoList(slopeGatewayInfo);
             if (list1 != null && !list1.isEmpty()){
                 slopeGatewayInfoServiceImpl.cancelAlarm(list1.get(0).getGatewaySn());
             }
        }
    }

    /**
     * 查询预警信息
     * 
     * @param id 预警信息主键
     * @return 预警信息
     */
    @Override
    public SlopeWarningInfo selectSlopeWarningInfoById(Long id)
    {
        return slopeWarningInfoMapper.selectSlopeWarningInfoById(id);
    }

    /**
     * 查询预警信息列表
     * 
     * @param slopeWarningInfo 预警信息
     * @return 预警信息
     */
    @DataScope(deptAlias = "s")
    @Override
    public List<SlopeWarningInfo> selectSlopeWarningInfoList(SlopeWarningInfo slopeWarningInfo)
    {
        return slopeWarningInfoMapper.selectSlopeWarningInfoList(slopeWarningInfo);
    }

    /**
     * 新增预警信息
     * 
     * @param slopeWarningInfo 预警信息
     * @return 结果
     */
    @Override
    public int insertSlopeWarningInfo(SlopeWarningInfo slopeWarningInfo)
    {
        slopeWarningInfo.setCreateTime(DateUtils.getNowDate());
        return slopeWarningInfoMapper.insertSlopeWarningInfo(slopeWarningInfo);
    }

    /**
     * 修改预警信息
     * 
     * @param slopeWarningInfo 预警信息
     * @return 结果
     */
    @Override
    public int updateSlopeWarningInfo(SlopeWarningInfo slopeWarningInfo)
    {
        slopeWarningInfo.setUpdateTime(DateUtils.getNowDate());
        return slopeWarningInfoMapper.updateSlopeWarningInfo(slopeWarningInfo);
    }

    /**
     * 批量删除预警信息
     * 
     * @param ids 需要删除的预警信息主键
     * @return 结果
     */
    @Override
    public int deleteSlopeWarningInfoByIds(Long[] ids)
    {
        return slopeWarningInfoMapper.deleteSlopeWarningInfoByIds(ids);
    }

    /**
     * 删除预警信息信息
     * 
     * @param id 预警信息主键
     * @return 结果
     */
    @Override
    public int deleteSlopeWarningInfoById(Long id)
    {
        return slopeWarningInfoMapper.deleteSlopeWarningInfoById(id);
    }
}
